package com.lemon.smartsafety.ui.adapter.common;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.lemon.smartsafety.entity.common.PanelRcvBaseDataI;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.common.LoggerHelper;

import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/3/24.
 * 通用的主页功能界面适配
 */
public class PanelRcvBaseAdapter<T> extends LemonRcvAdapter<PanelRcvBaseDataI> {
    private RecyclerTClickListener<PanelRcvBaseDataI> mClickListener;
    private LoggerHelper loggerHelper = new LoggerHelper(PanelRcvBaseAdapter.class);
    private PanelRcvBaseAdapter(@Nullable List<PanelRcvBaseDataI> data) {
        super(data);
    }
    public PanelRcvBaseAdapter(@Nullable List<PanelRcvBaseDataI> data,RecyclerTClickListener<PanelRcvBaseDataI> listener) {
        super(data);
        this.mClickListener = listener;
    }

    @Override
    public Object getItemType(PanelRcvBaseDataI panelRcvBaseDataI) {
        return panelRcvBaseDataI;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object obj) {
        PanelRcvBaseDataI dataI = (PanelRcvBaseDataI)obj;
        RcvViewType.PanelViewType myType = dataI.iGetViewType();

        if (myType == RcvViewType.PanelViewType.TYPE_SECTION_HEAD) {
            return new SectionHeadView(dataI.getTitleI());
        }else if(myType == RcvViewType.PanelViewType.TYPE_TITLE){
            return new RcvItemTitleView(dataI.getTitleI());
        }else if(myType == RcvViewType.PanelViewType.TYPE_COMMON_ITEM){
            return new PanelRcvBaseAdapterItem(mClickListener);
        }
        return new SectionHeadView();
    }
}
